package com.young.util;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.CodeSignature;

public class JoinPointContextUtil {

	public static Map<String, Object> getJoinPointContextMap(JoinPoint jp) {
		Map<String, Object> context = new HashMap<String, Object>();
		context.put("_jp", jp);
		context.put("_this", jp.getThis());
		context.put("_target", jp.getTarget());
		context.put("_args", jp.getArgs());
		Signature sig = jp.getSignature();
		if (sig instanceof CodeSignature) {
			CodeSignature codeSig = (CodeSignature) sig;
			String[] paramNames = codeSig.getParameterNames();
			Object[] args = jp.getArgs();
			for(int i = 0; i < paramNames.length; i++) {
				context.put(paramNames[i], args[i]);
			}
		}
		return context;
	}
}
